#!/bin/bash
REPO="code.byted.org/bytertc/whiteboard_server"
RUN_NAME="bytertc.server.whiteboard"
BUILD_TIME=$(date +"%Y%m%d%H%M%S")

mkdir -p output/bin output/conf
cp script/bootstrap.sh output 2>/dev/null
chmod +x output/bootstrap.sh
cp script/bootstrap.sh output/bootstrap_staging.sh
chmod +x output/bootstrap_staging.sh
find conf/ -type f ! -name "*_local.*" | xargs -I{} cp {} output/conf/

# build with stats
GO_LDFLAGS="$GO_LDFLAGS -X ${REPO}/biz/pkg/stats.Name=${RUN_NAME}"
GO_LDFLAGS="$GO_LDFLAGS -X ${REPO}/biz/pkg/stats.Version=${BUILD_VERSION}"
GO_LDFLAGS="$GO_LDFLAGS -X ${REPO}/biz/pkg/stats.BuildTime=${BUILD_TIME}"
GO_LDFLAGS="$GO_LDFLAGS -X ${REPO}/biz/pkg/stats.GitSHA1=${GitSHA1}"

go build -ldflags "$GO_LDFLAGS" -o output/bin/${RUN_NAME} ./cmd/server
